

	/***********************************************************************************
	*	This class adds methods and helper information specific entire frames in the instrumentation business case
	*	This provides structure in the instrumentation business case to working with entire frames of information
	***********************************************************************************/

public class FrameFilterFramework extends InstrumentationFilterFramework{
	
	protected boolean writeFrameToOutputFilterPort(Frame frame){
		//writes the entire frame to the output port, if it is full
		//else return false;
		if (frame.isFullFrame()){
			this.writeMeasurementToFilterOutputPort(Measurement.TIME, frame.getTime());
			this.writeMeasurementToFilterOutputPort(Measurement.VELOCITY, frame.getVelocity());
			this.writeMeasurementToFilterOutputPort(Measurement.ALTITUDE, frame.getAltitude());
			this.writeMeasurementToFilterOutputPort(Measurement.PRESSURE, frame.getPressure());
			this.writeMeasurementToFilterOutputPort(Measurement.TEMPERATURE, frame.getTemperature());
			this.writeMeasurementToFilterOutputPort(Measurement.PITCH, frame.getPitch());
			return true;
		}
		return false;
	}
	
	class Frame{
		private long time;
		private double velocity, altitude, pressure, temperature, pitch;
		private boolean timeSet, velocitySet, altitudeSet, pressureSet, temperatureSet, pitchSet;
		
		Frame(){
			
		}

		public boolean addMeasurement(int id, long measurement){
			//if the appropriate measure is already set, returns false;
			//else sets the measurement
			if ( id == Measurement.TIME.getID() && !this.isTimeSet())
			{
				this.setTime(measurement);
				return true;

			} // if

			else if ( id == Measurement.VELOCITY.getID() && !this.isVelocitySet())
			{	
				//convert to double and set
				this.setVelocity(Double.longBitsToDouble(measurement));
				return true;
			} // if
			
			else if ( id == Measurement.ALTITUDE.getID() && !this.isAltitudeSet())
			{	
				//convert to double and set
				this.setAltitude(Double.longBitsToDouble(measurement));
				return true;
			} // if

			else if ( id == Measurement.PRESSURE.getID() && !this.isPressureSet())
			{	
				//convert to double and set
				this.setPressure(Double.longBitsToDouble(measurement));
				return true;
			} // if

			else if ( id == Measurement.TEMPERATURE.getID() && !this.isTemperatureSet())
			{
				//convert to double and set
				this.setTemperature((Double.longBitsToDouble(measurement)));
				return true;
			} // if
			
			else if ( id == Measurement.PITCH.getID() && !this.isPitchSet())
			{
				//convert to double and set
				this.setPitch((Double.longBitsToDouble(measurement)));
				return true;
			} // if
			
			return false;
		}
		public void setVelocity(double velocity) {
			this.velocity = velocity;
			velocitySet = true;
		}

		public double getVelocity() {
			return velocity;
		}

		public void setAltitude(double altitude) {
			this.altitude = altitude;
			altitudeSet = true;
		}

		public double getAltitude() {
			return altitude;
		}

		public void setPressure(double pressure) {
			this.pressure = pressure;
			pressureSet = true;
		}

		public double getPressure() {
			return pressure;
		}

		public void setTemperature(double temperature) {
			this.temperature = temperature;
			temperatureSet = true;
		}

		public double getTemperature() {
			return temperature;
		}

		public void setPitch(double pitch) {
			this.pitch = pitch;
			pitchSet = true;
		}

		public double getPitch() {
			return pitch;
		}

		public void setTime(long time) {
			this.time = time;
			timeSet = true;
		}

		public long getTime() {
			return time;
		}
		
		public boolean isTimeSet(){
			return timeSet;
		}
		public boolean isVelocitySet(){
			return velocitySet;
		}
		public boolean isAltitudeSet(){
			return altitudeSet;
		}
		public boolean isPressureSet(){
			return pressureSet;
		}
		public boolean isTemperatureSet(){
			return temperatureSet;
		}
		public boolean isPitchSet(){
			return pitchSet;
		}
		public boolean isFullFrame(){
			//checks if the data for the entire frame is present 
			return (timeSet && velocitySet && altitudeSet && pressureSet && temperatureSet && pitchSet);
		}
	}
}
